package cn.hamster3.mc.plugin.core.bukkit.command.core.sub;

import cn.hamster3.mc.plugin.core.bukkit.command.ChildCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class SystemCommand extends ChildCommand {
    public static final SystemCommand INSTANCE = new SystemCommand();

    private SystemCommand() {
    }

    @Override
    public @NotNull String getName() {
        return "system";
    }

    @Override
    public @NotNull String getUsage() {
        return "system";
    }

    @Override
    public boolean hasPermission(@NotNull CommandSender sender) {
        return true;
    }

    @Override
    public @NotNull String getDescription() {
        return "查看系统属性";
    }

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
        if (args.length < 1) {
            sender.sendMessage(System.getProperties().toString());
            return true;
        }
        sender.sendMessage(args[0] + "=" + System.getProperty(args[0], ""));
        return true;
    }

    @Override
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
        if (args.length == 1) {
            String lowerCase = args[0].toLowerCase();
            return System.getProperties().keySet()
                    .stream()
                    .map(Object::toString)
                    .filter(o -> o.toLowerCase().startsWith(lowerCase))
                    .collect(Collectors.toList());
        }
        return Collections.emptyList();
    }
}
